package com.cy.law.utils;

import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;

public class XStreamIntConverter extends AbstractSingleValueConverter {
    public XStreamIntConverter() {
        super();
    }

    @Override
    public String toString(Object obj) {
        return super.toString(obj);
    }

    @Override
    public boolean canConvert(Class type) {
        return type == int.class || type == Integer.class;
    }

    @Override
    public Object fromString(String str) {
        if (isEmpty(str)) {
            return null;
        }
        long value = Long.decode(str).longValue();
        if (value < Integer.MIN_VALUE || value > 0xFFFFFFFFl) {
            throw new NumberFormatException("For input string: \"" + str + '"');
        }
        return new Integer((int) value);
    }

    public static boolean isEmpty(Object str) {
        return (str == null || "".equals(str));
    }
}
